<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加项目</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../css/index.css">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">学号</label>
      <div class="layui-input-inline">
        <input type="text" id="studentid" name="studentid" lay-verify="required" placeholder="学号不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">学生姓名</label>
      <div class="layui-input-inline">
        <input type="text" id="studentname" name="studentname" lay-verify="required" placeholder="学生姓名不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">性别</label>
      <div class="layui-input-inline">
        <select id="agend" name="agend" lay-filter="agend" lay-verify="required">
          <option value="">请选择性别</option>
          <option value="1">男</option>
          <option value="2">女</option>
        </select>
      </div>
    </div>
    
     <div class="layui-form-item">
      <label class="layui-form-label">是否毕业</label>
      <div class="layui-input-inline">
        <select id="isgraduat" name="isgraduat" lay-filter="isgraduat" lay-verify="required">
          <option value="">请选择是否毕业</option>
          <option value="1">在校生</option>
          <option value="2">已毕业</option>
        </select>
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">电话号码</label>
      <div class="layui-input-inline">
        <input type="text" id="mobile" name="mobile"  lay-verify="required" placeholder="电话不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
		 	<label class="layui-form-label">所属学院</label>
			<div class="layui-input-inline collegename">
				<select name="collegename" id="collegename" lay-filter="collegename">
					<option value='0'>请选择学院</option>
				</select>
			</div>
		 </div>
	  <div class="layui-form-item">
	  	<label class="layui-form-label">所属专业</label>
		<div class="layui-input-inline professionalname">
			<select name="professionalname" id="professionalname" lay-filter="professionalname">
				<option value='0'>请选择专业</option>
			</select>
		</div>
	 </div>
	 
    <div class="layui-form-item">
      <label class="layui-form-label">班级</label>
      <div class="layui-input-inline">
        <select name="classname" id="classname" lay-filter="classname" lay-verify="required">
          <option value="0">请选择班级</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">入学年份</label>
      <div class="layui-input-inline">
        <input type="text" id="grade" name="grade"  placeholder="年份不能为空" autocomplete="off" class="layui-input">
      </div>
     </div>
     <div class="layui-form-item">
      <div class="layui-form-item">
      <label class="layui-form-label">宿舍地址</label>
      <div class="layui-input-inline">
        <input type="text" id="address" name="address"  placeholder="学生地址不能为空" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux" style="color:red">填写格式：15-222</div>
     </div>
     <div class="layui-form-item">
     <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
        <input type="text" id="note" name="note" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
  </div>

 <script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script> 
 <script src="../../js/jquery-3.3.1.js" charset="utf-8"></script>
<script src="../../js/provincialLevel.js" charset="utf-8"></script>
<script type="text/javascript">
 layui.use(['table','jquery','form','layer'], function(){
  var table = layui.table;
  var $ = layui.jquery;
  var form=layui.form;
  var layer = layui.layer;
  
    ThreeLevel("collegename",form);
  
    //监听提交,添加事件
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
 			
 			if(!new RegExp("^1[345789]\\d{9}$").test(data.field.mobile)){
			     layer.msg("电话号码格式错误");
			      return;
			}
			if(data.field.address != null || !data.field.address.equals("")){
				if(!new RegExp("[^0-9]").test(data.field.address)){//必须输入带有字符串的才可以
			     layer.msg("宿舍地址格式不正确");
			      return;
				}
			}
			
 			var studentid = $("#studentid").val();
			var studentname = $("#studentname").val();
			var isgraduat = $("#isgraduat").val();
			var agend = $("#agend").val();
		    var mobile = $("#mobile").val();
		    var collegename = $("#collegename").val();
		    var professionalname = $("#professionalname").val();
		    var classname = $("#classname").val();
		    var grade = $("#grade").val();
		    var address = $("#address").val();
		    var note = $("#note").val();
			
			var param = "?studentid=" + studentid + "&studentname=" +studentname + "&isgraduat="
						+ isgraduat + "&agend=" + agend + "&mobile=" + mobile + "&classid=" + classname
						+ "&grade=" + grade + "&address=" + address + "&note=" +note;
			//alert(param)
			$.ajax({
				url:"../../studentinfo/addstudent" + param,
				type:"POST",
				data:null,
				dataType : "json",
				xhrFields :{
					withCredentials: true
				},
				contentType:'application/json;charset=UTF-8',
				success:function(e){
					//alert(e.msg)
					if(e.code == 0){
						layer.msg(e.msg,{icon:6}); 
					}else{
						layer.msg(e.msg,{icon:5});
						return;
					}
					
					setTimeout(function(){
						parent.layui.table.reload('LAY-app-content-list'); //重载表格
      					parent.layer.close(index); //再执行关闭 
					},1*1000)
					
				},
				error:function(e){
					layer.msg(e.msg,{icon:5});
					
				}
			})
      	return false;
    });
  
  			
  			
  			
  			
  			function callAJAX(reqType, reqURL, reqPara) {
				var returndata = '';
				$.ajax({
					type : reqType,
					url : reqURL,
					datatype : 'json',
					async : false, //不做异步刷新，解决执行顺讯问题
					data : reqPara,
					success : function(data) {
						returndata = data;
					},
					error : function() {
						returndata = '';
					}
				});
				return returndata;
			}
  			
  			
  			
			/*新增弹框三级联动*/
			function ThreeLevel(selectId,form){
				/*品牌菜单*/
				var reqType = 'post';
				var reqURL = '../../dropdown/getcollooge2';
				var reqPara = {};
				var stageData = callAJAX(reqType, reqURL, reqPara)
				if (stageData != '' && stageData != undefined) {
					//alert(stageData.code)
					if (stageData.code == 0) {
						$('#' + selectId).html(""); //获取id为selectId指定的控件内容
						var str = "<option value='0'>请选择学院</option>";
						for (var i = 0; i < stageData.resultObject.length; i++) {
							str += '<option value=' + stageData.resultObject[i].collegeid + '>' + stageData.resultObject[i].collegename + '</option>';
						}
						$('#' + selectId).append(str);
						form.render("select");
					} else {
						
						layer.msg('未获取到学院信息！', function() {});
					}
				} else {
					
					layer.msg('未获取到学院信息！', function() {});
				}
			
			/*类型菜单*/
			form.on('select(collegename)',function(data){
				$('.professionalname select').empty();//选择省的时候清空城市地区的值
				//$('.querytypename select').html('<option value="">城市</option>');
				$('.classname select').empty();
				$('.classname select').html('<option value="">请选择专业</option>');
				
				var collegename = data.value;
				var param = '?collegeid=' + collegename;
				
				var reqType = 'post';
				var reqURL = '../../dropdown/getprofessional2' + param;
				var reqPara = {};
				var stageData = callAJAX(reqType, reqURL, reqPara)
				if (stageData != '' && stageData != undefined) {
					if (stageData.code == 0) {
						$('#' + 'professionalname').html(""); //获取id为selectId指定的控件内容
						var str = "<option value='0'>请选择专业</option>";
						for (var i = 0; i < stageData.resultObject.length; i++) {
							str += '<option value=' + stageData.resultObject[i].professionalid + '>' + stageData.resultObject[i].professionalname + '</option>';
						}
						$('#' + 'professionalname').append(str);
						form.render("select");
					} else {
						layer.msg('未获取到专业信息！', function() {});
					}
				} else {
					layer.msg('未获取到专业信息！', function() {});
				}
			});
			
			/*配置菜单*/
			form.on('select(professionalname)',function(data){
				$('.classname select').empty();//选择市的时候清空区的值
				$('.classname select').html('<option value="0">请选择班级</option>');
				var professionalname = data.value;
				var param2 = '?professionalid=' + professionalname;
				//alert(param2);
			
				var reqType = 'post';
				var reqURL = '../../dropdown/getclass2' + param2;
				var reqPara = {};
				var stageData = callAJAX(reqType, reqURL, reqPara)
				if (stageData != '' && stageData != undefined) {
					if (stageData.code == 0) {
						$('#' + 'classname').html(""); //获取id为selectId指定的控件内容
						var str = "<option value='0'>请选择班级</option>";
						for (var i = 0; i < stageData.resultObject.length; i++) {
							str += '<option value=' + stageData.resultObject[i].classid + '>' + stageData.resultObject[i].classname + '</option>';
						}
					
						$('#' + 'classname').append(str);
						form.render("select");
					} else {
						layer.msg('未获取到班级信息！', function() {});
					}
				} else {
					layer.msg('未获取到班级信息！', function() {});
				}
			});
			}
  
  		
});
</script>
</body>
</html>